import { defineStore } from 'pinia'
export const userData = defineStore('userData', {
    unistorage: true, // 是否持久化
    state: () => {
        return {
            id: '',
            token:null,
            nickName:null,
            openid:null,
            photo:null,
            sex:0,
            phone:null,
            isVip:0,
            isRegisterHealth:0,
            isSecured:0,
            idCard:null,
            age:null,
            isRealName:null,
			isPayPwd:false


        }
    },
    actions: {
        setUserData({id,token,nickName,openid,photo,sex,phone,isVip,isRegisterHealth,isSecured,idCard,age,isRealName,payPwd}:any) {
            this.id = id||this.id;
            this.token = token||this.token;
            this.nickName = nickName||this.nickName;
            this.openid = openid||this.openid;
            this.photo = photo||this.photo;
            this.sex = sex||this.sex;
            this.phone = phone||this.phone;
            this.idCard = idCard;
            this.age = age||this.age;

            if(isRealName||isRealName===0){
                this.isRealName = isRealName;
            }
            if(isVip||isVip===0){
                this.isVip =  isVip;
            }
            if(isRegisterHealth||isRegisterHealth===0){
                this.isRegisterHealth =  isRegisterHealth;
            }
            if(isSecured||isSecured===0){
                this.isSecured =  isSecured;
            }
			if(payPwd!=null&&payPwd!=''){
				this.isPayPwd = true
			}else{
				this.isPayPwd = false
			}
        },
        clearUserData(){
            this.id = '';
            this.token = null;
            this.nickName = null;
            this.openid = null;
            this.photo = null;
            this.sex = 0;
            this.phone = null;
            this.isVip = 0;
            this.isRegisterHealth = 0;
            this.isSecured = 0;
            this.idCard = null;
            this.isRealName = null;
        }
    }
})

// export default defineStore('userData', {
//     unistorage: true,
//     state: () => ({ id: '123456',accessToken: null}),
//     // getters: {
//     //   double: (state) => state.count * 2,
//     // },
//     actions: {
//       setUserData({id,accessToken}:any) {
//         this.id = id;
//         this.id = accessToken;
//       },
//     },
//   })

//   export const userData = defineStore('counter', () => {
//     const id = ref(11111111)
//     function setUserData() {
//       id.value = 44444444
//     }
  
//     return { id, setUserData }
//   })